package com.pxmeta.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.skill.entity.UserSkill;
import com.pxmeta.skill.service.IUserSkillService;
import com.pxmeta.user.entity.User;
import com.pxmeta.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "用户技能管理",tags = "用户技能")
@RequestMapping(value = "/userSkill")
@CrossOrigin
@RequiredArgsConstructor
public class UserSkillController {

    private final IUserSkillService userSkillService;

    private final IUserService userService;

    @GetMapping("/getUserSkillList")
    @ApiOperation("获取用户技能列表")
    public AjaxResult getUserSkillList(@RequestParam Integer page,
                                       @RequestParam Integer size) {

        LambdaQueryWrapper<UserSkill> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(UserSkill::getCreateTime);
        Page<UserSkill> result = userSkillService.page(new Page<>(page, size), wrapper);

        for (UserSkill record : result.getRecords()) {
            Long userId = record.getUserId();
            User user = userService.getById(userId);
            String account = user.getAccount();
            record.setAccount(account);
        }
        return AjaxResult.successPage(result.getRecords(),result.getTotal());
    }


    @PutMapping("/verifyUserSkill")
    @ApiOperation("审核用户技能")
    public AjaxResult verifyUserSkill(@RequestParam Long userId,
                                      @RequestParam Long userSkillId,
                                      @RequestParam Integer status) {
        userSkillService.verifyUserSkill(userId, userSkillId);
        return AjaxResult.success();
    }

}
